package com.leyou.order.controller;

import com.leyou.order.dto.OrderDTO;
import com.leyou.order.service.OrderService;
import com.leyou.order.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;
    @PostMapping(value = "/order",name = "下单")
    public ResponseEntity<Long> createOrder(@RequestBody OrderDTO order){
        Long orderId = orderService.createOrder(order);
        return ResponseEntity.ok(orderId);
    }

    @GetMapping(value = "/order/{id}",name = "根据id查询订单信息")
    public ResponseEntity<OrderVO> findById(@PathVariable("id") Long id){
        OrderVO orderVO = orderService.findById(id);
        return ResponseEntity.ok(orderVO);
    }
    @GetMapping(value = "/order/url/{id}",name = "根据订单号生产微信支付的url地址")
    public ResponseEntity<String> unifiedorder(@PathVariable("id") Long id){
        String codeUrl = orderService.unifiedorder(id);
        return ResponseEntity.ok(codeUrl);
    }
    @GetMapping(value = "/order/state/{id}",name = "根据订单号生产微信支付的url地址")
    public ResponseEntity<Integer> queryOrderState(@PathVariable("id") Long id){
        Integer state = orderService.queryOrderState(id);
        return ResponseEntity.ok(state);
    }



}
